/**
 * %统一搜索%
 * %1.0%
 */
package com.leehom.arch.base.serializer.xstream;

import org.joda.time.DateTime;

import com.leehom.arch.base.utils.DateTimeUtils;
import com.thoughtworks.xstream.converters.SingleValueConverter;

/**
 * @类名: ISO8601DateConverter
 * @说明: ISO8601日期转换器, 解决XStream序列化ISO8601日期格式
 * 
 * @author leehom
 * @Date 2010-6-15 下午06:09:19 
 * 修改记录：
 * 
 * @see
 */
public class ISO8601DateConverter implements SingleValueConverter {

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.thoughtworks.xstream.converters.SingleValueConverter#fromString(java
	 * .lang.String)
	 */
	
	public Object fromString(String str) {
		return DateTimeUtils.ISO8601StringToDateTime(str);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.thoughtworks.xstream.converters.SingleValueConverter#toString(java
	 * .lang.Object)
	 */
	
	public String toString(Object obj) {
		return DateTimeUtils.ISO8601DateToString((DateTime) obj);
			
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.thoughtworks.xstream.converters.ConverterMatcher#canConvert(java.
	 * lang.Class)
	 */
	
	public boolean canConvert(Class type) {
		return type.equals(DateTime.class);
	}

}
